/**
 * 
 */
package cs3201.westga.edu.project_2;

/**
 * This is the Triangle class. A Triangle can be described by its base and height.
 * @author Cody Stamps
 *
 */
public class Triangle {
	
	private double base;
	private double height;
	
	/**
	 * Constructor for class Triangle
	 * @param base
	 * @param height
	 */
	public Triangle(double _base, double _height) {
		setBase(_base);
		setHeight(_height);
	}
	
	/**
	 * getBase() - returns the current base of the triangle
	 * @return the base
	 */
	public double getBase() {
		return base;
	}
	
	/**
	 * setBase() sets the base of the triangle
	 * @param base the base to set
	 * @throws IllegalArgumentException  if the base to be set is < 0
	 */
	public void setBase(double base) {
		//REQUIRES the base be greater than 0
		//MODIFIES base
		//EFFECTS changes the base
		if (base <= 0 ){
			throw new IllegalArgumentException("Error: Invalid input. The Base must be greater than 0.");
		}
		this.base = base;
	}
	
	/**
	 * getHeight() - returns the current height of this triangle
	 * @return the height
	 */
	public double getHeight() {
		return height;
	}
	
	/**
	 * setHeight() - sets the height of the triangle.
	 * @param height the height to set
	 * @throws IllegalArgumentException - the height must be greater than 0.
	 */
	public void setHeight(double height) {
		//REQUIRES the height to be set be greater than 0
		//MODIFIES height
		//EFFECTS changes the height
		if (height <= 0){
			throw new IllegalArgumentException("Error: Invalid Height. The Height must be greater than 0");
		}
		this.height = height;
	}
	
	/**
	 * hashCode() - generates a hashcode version of this triangle.
	 * @return the hashcode version of this triangle
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(base);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(height);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}
	
	/**
	 * equals() - test if an object is equal to this triangle
	 * @return - true if object is equal, else false.
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) //checks obj to this triangle
			return true; //if the same triangle return true.
		if (obj == null) //checks to make sure obj is not null
			return false; //if it is return false.
		if (getClass() != obj.getClass()) //checks to make sure obj's class is the same as this triangle
			return false; //if not return false.
		Triangle other = (Triangle) obj; //cast the obj as a triangle object.
		if (Double.doubleToLongBits(base) != Double // checks to see if other's base is the same as this triangles base
				.doubleToLongBits(other.base))
			return false; //if it is not, return false.
		if (Double.doubleToLongBits(height) != Double // checks to see if other's height is the same as this triangle's height
				.doubleToLongBits(other.height))
			return false; //if it is not, return false
		return true; //else return true.
	}
	
	/**
	 * toString() - returns a string representation of this triangle.
	 * @return - the string representation of this triangle. 
	 */
	@Override
	public String toString() {
		return "Traingle [base=" + base + ", height=" + height + "]";
	}
	
	/**
	 * resize(double) - adjust the base and height according to the amount.
	 * @param amount - the size to readjust.
	 */
	public void resize(double amount){
		//REQUIRES The amount > 0
		//MODIFIES Base and Height
		//EFFECTS The Base and height will be multiplied by the amount.
		if (amount <= 0){
			throw new IllegalArgumentException("Error: The amount by which you want to resize is invalid.");
		}
		base = base * amount;
		height = height * amount;
		System.out.println("The base is now: " + base);
		System.out.println("The Height is now: " + height); 
	}
	
	/**
	 * getArea() - calculates the area of this triangle.
	 * @return - the area of this triangle
	 */
	public double getArea(){
		return (base*height/2);
	}

}
